<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Transition</title>
  <style>
    div {
      width: 200px;
      height: 200px;
      background-color: pink;
      display: none;
    }

    div.active {
      display: block;
    }

    .animated {
      animation-duration: .3s;
      animation-fill-mode: both;
    }

    .slide-down {
      animation-name: slideDown;
    }

    .slide-up {
      /* animation-direction: reverse; */
      animation-name: slideUp;
    }

    @keyframes slideDown {
      to {
        height: 300px;
        background-color: blue;
      }
    }

    @keyframes slideUp {
      from {
        height: 300px;
        background-color: blue;
      }
    }
  </style>
</head>
<body>
  <p>
    <button type="button" data-action="active">Active</button>
    <button type="button" data-action="animated">Animated</button>
    <button type="button" data-action="slide-down">SlideDown</button>
    <button type="button" data-action="slide-up">SlideUp</button>
  </p>
  <div id="div"></div>
  <script>
    document.addEventListener('click', ({target}) => {
      const className = target.dataset.action;

      if (!className) return;

      div.classList.toggle(className);
    });
  </script>
</body>
</html>